/////////////////////////////////////////////////////////////////////////////////////
//Json数据排序比较器
function compare(propertyName) { 
	return function (object1, object2) { 
		var value1 = object1[propertyName]; 
		var value2 = object2[propertyName]; 
		if (value1 < value2) { 
			return -1; 
		} 
		else if (value1 > value2) { 
			return 1; 
		} 
		else { 
			return 0; 
		} 
	} 
} 
//初始化数据
var Json,ROLE;
function initData(){	
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"defaultWorkFlow/flowDetails?id="+RB.Sstrorage(false,'flowid'),
		//url: SERVER+"defaultWorkFlow/flowDetails?id=df84a90682144b3e825f8fa01e2a5acc",
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){	
			Json = json;
			initBasic(json.respBody.flowTypexml.flowName);
			initFormList(json.respBody.flowHtmltemplates);
			initTool();
			initStepList(json.respBody.flowApproves);
        },
        error: function(){
            alert("error");
    	}
	});
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER+"role",
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			ROLE = json;
        },
        error: function(){
            alert("getRoleList error");
    	}
	});
}
//初始化基本信息
function initBasic(json){
	delete Json.respBody.flowTypexml.createDate;
	if (Json.respBody.flowTypexml.icons.length>0){		
		$(".rb_newflow_icon").html("<img src='"+IMGURL+Json.respBody.flowTypexml.icons+"'/>");
	}
	$("#flowName").val(json);
	$("#flowName").unbind("blur").blur(function(e) {
        Json.respBody.flowTypexml.flowName = $("#flowName").val();
		Json.respBody.flowTypexml.flowType = $("#flowName").val();
		for (var i in Json.respBody.flowApproves){
			Json.respBody.flowApproves[i].flowName = $("#flowName").val();
		}
    });
}
//初始化工具栏
function initTool(){
	$(".rb_newflow_kongjian").find("li").click(function(){
		var flowId = Json.respBody.flowTypexml.id;
		var x = 0;
		var y = 99;
		var rand = "new_"+parseInt(Math.random() * (x - y + 1) + y);
		switch($(this).index()){
		case 0:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_wenben widgetItem' id=\""+rand+"\"><div>新创建的文本控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的文本控件","chineseName" : "新创建的文本控件","widgetType" : "editText","defaultValue" : "","options" : "","isNull" : "0","isValid" : "1","lengthValid" : 200,"sortNo" : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的文本控件",widgetType : "editText",isNull : "0",isValid : "0"});
			}
			break;
		case 1:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_danxuan widgetItem' id=\""+rand+"\"><div>新创建的单选控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的单选控件","chineseName" : "新创建的单选控件","widgetType" : "select","defaultValue" : "","options" : "","isNull" : "0","isValid" : "1","lengthValid" : 200,"sortNo" : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的单选控件",widgetType : "select",isNull : "0",isValid : "0"});
			}
			break;
		case 2:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_duoxuan widgetItem' id=\""+rand+"\"><div>新创建的多选控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的多选控件",chineseName : "新创建的多选控件",widgetType : "checkbox",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的多选控件",widgetType : "checkbox",isNull : "0",isValid : "0"});
			}
			break;
		case 3:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_anniu widgetItem' id=\""+rand+"\"><div>新创建的按钮控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的按钮控件",chineseName : "新创建的按钮控件",widgetType : "button",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的按钮控件",widgetType : "button",isNull : "0",isValid : "0"});
			}
			break;
		case 4:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_riqi widgetItem' id=\""+rand+"\"><div>新创建的日期控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的日期控件",chineseName : "新创建的日期控件",widgetType : "date",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的日期控件",widgetType : "date",isNull : "0",isValid : "0"});
			}
			break;
		case 5:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_tupian widgetItem' id=\""+rand+"\"><div>新创建的图片控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的图片控件",chineseName : "新创建的图片控件",widgetType : "image",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的图片控件",widgetType : "image",isNull : "0",isValid : "0"});
			}
			break;
		case 6:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_files widgetItem' id=\""+rand+"\"><div>新创建的文件控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的文件控件",chineseName : "新创建的文件控件",widgetType : "file",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的文件控件",widgetType : "file",isNull : "0",isValid : "0"});
			}
			break;
			case 7:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_shengyin widgetItem' id=\""+rand+"\"><div>新创建的声音控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的声音控件",chineseName : "新创建的声音控件",widgetType : "voice",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的声音控件",widgetType : "voice",isNull : "0",isValid : "0"});
			}
			break;
			case 8:
			$('.gbin1-list').prepend("<li class='rb_newflow_kongjian_roleselect widgetItem' id=\""+rand+"\"><div>新创建的角色选择控件</div><input name='value' type='hidden' value=''><div></div></li>");
			Json.respBody.flowHtmltemplates.push({"id" : rand,"flowId" : flowId,"englishName" : "新创建的角色选择控件",chineseName : "新创建的角色选择控件",widgetType : "selectperson",defaultValue : "",options : "",isNull : "0",isValid : "1",lengthValid : 200,sortNo : 0});
			for (var i in Json.respBody.flowApproves){
				Json.respBody.flowApproves[i].flowhtmls.push({displayId : "",activeId : Json.respBody.flowApproves[i].id,isDisplay : "0",isEdit : "0",id : rand,chineseName : "新创建的角色选择控件",widgetType : "selectperson",isNull : "0",isValid : "0"});
			}
			break;
		}
		initFormListDrop();
		initFormListClick();
	});
}
//初始化表单列表
function initFormList(json){
	for (var i=0;i<json.length;i++){
		var widgetType = json[i].widgetType;
		var widgetTypeCss;
		switch(widgetType){
			case "editText":
				widgetTypeCss = "rb_newflow_kongjian_wenben";
			break;
			case "textView":
				widgetTypeCss = "rb_newflow_kongjian_textview";
			break;
			case "select":
				widgetTypeCss = "rb_newflow_kongjian_danxuan";
			break;
			case "checkbox":
				widgetTypeCss = "rb_newflow_kongjian_duoxuan";
			break;
			case "file":
				widgetTypeCss = "rb_newflow_kongjian_files";
			break;
			case "selectperson":
				widgetTypeCss = "rb_newflow_kongjian_roleselect";
			break;
			case "image":
				widgetTypeCss = "rb_newflow_kongjian_tupian";
			break;
			case "voice":
				widgetTypeCss = "rb_newflow_kongjian_shengyin";
			break;
			case "button":
				widgetTypeCss = "rb_newflow_kongjian_anniu";
			break;
			default:
				widgetTypeCss = "rb_newflow_kongjian_wenben";
			break;
		}
		$(".gbin1-list").append("<li class='"+widgetTypeCss+" widgetItem' id='"+json[i].id+"'><div>"+json[i].chineseName+"</div><input name='value' type='hidden' value='"+json[i].options+"'><div></div></li>");
		initFormListDrop();
		initFormListClick();
	}
}
//初始化表单列表拖拽
function initFormListDrop(){
	$('.gbin1-list').sortable().bind('sortupdate', function() {
		$('.gbin1-list').find("li").each(function(arg, element) {
            var idstr = $(this).attr("id");
			//alert($(this).text());
			for (var i in Json.respBody.flowHtmltemplates){
				if (Json.respBody.flowHtmltemplates[i].id == idstr){
					Json.respBody.flowHtmltemplates[i]["sortNo"] = arg;
				}
			}
        });
	});
}
function show_json(){
	dump(Json);
}
//初始化表单列表点击
function initFormListClick(){
	$('.gbin1-list').find("li").click(function(){
		var id = $(this).attr('id');
		$('.gbin1-list').find("li").each(function() {
			$(this).css("background-color","transparent");
		});
		$(this).css("background-color","#9CF");
		$("#kongjianName").val($(this).find("div").text());
		$("#kongjianName").unbind("blur").blur(function(e) {
            kongjianSave(id);
        });
		$("#kongjianValue").val($(this).find("input").val());
		$("#kongjianValue").unbind("blur").blur(function(e) {
            kongjianSave(id);
        });
		$(this).find("div:last-child").unbind("click").click(function(){kongjianDelete(id)});
	});	
}
//保存表单控件
function kongjianSave(id){
	var kjName = $("#kongjianName").val();
	var kjValue = $("#kongjianValue").val()
	$("#"+id).find("div:first-child").text(kjName);
	$("#"+id).find("input").val(kjValue);
	for (var i in Json.respBody.flowHtmltemplates){
		if (Json.respBody.flowHtmltemplates[i].id == id){
			Json.respBody.flowHtmltemplates[i]["chineseName"] = kjName;
			Json.respBody.flowHtmltemplates[i]["options"] = kjValue;
		}
	}
	for (var i in Json.respBody.flowApproves){
		for (var j in Json.respBody.flowApproves[i].flowhtmls){
			if (Json.respBody.flowApproves[i].flowhtmls[j].id == id){				
				Json.respBody.flowApproves[i].flowhtmls[j]["chineseName"] = kjName;
			}
		}	
	}
}
//删除表单控件
function kongjianDelete(id){
	$("#"+id).remove();
	for (var i in Json.respBody.flowHtmltemplates){
		if (Json.respBody.flowHtmltemplates[i].id == id){
			delete Json.respBody.flowHtmltemplates[i];
		}
	}
	for (var i in Json.respBody.flowApproves){
		for (var j in Json.respBody.flowApproves[i].flowhtmls){
			if (Json.respBody.flowApproves[i].flowhtmls[j].id == id){
				delete Json.respBody.flowApproves[i].flowhtmls[j];
			}
		}	
	}		
}
//初始化步骤
function initStepList(json){
	//排序
	json.sort(compare("step"));
	for (var i=0;i<json.length;i++){
		if (i==0){
			$('.gbin2-list').append("<li id='"+json[i].id+"' step='"+json[i].step+"'><div>"+json[i].activityName+"</div><div style='display:none'></div></li>");
		}else{
			$('.gbin2-list').append("<li id='"+json[i].id+"' step='"+json[i].step+"'><div>"+json[i].activityName+"</div><div></div></li>");	
		}
	}
	initStepListDrop();
	initStepListClick();
}
//初始化步骤拖拉
function initStepListDrop(){
	$('.gbin2-list').sortable().bind('sortupdate', function() {
		$('.gbin2-list').find("li").each(function(index, element) {
            var idstr = $(this).attr("id");
			$(this).attr("step" , index+1);
			//alert(index);
			for (var i in Json.respBody.flowApproves){
				if (Json.respBody.flowApproves[i].id == idstr){
					Json.respBody.flowApproves[i].step = index+1;
				}
			}
        });
	});
}
//创建节点
function createFlowStep(){
	var x = 0;
	var y = 99;
	var rand = "new_"+parseInt(Math.random() * (x - y + 1) + y);
	var nowLastStep = parseInt($('.gbin2-list li:last-child').attr("step"));
	$('.gbin2-list').append("<li id='"+rand+"' step='"+(nowLastStep+1)+"'><div>新的节点</div><div></div></li>");
	//通过转成字符串后再转回Json格式来防止浅复制造成的修改值影响到原数据的问题
	var newFlowStepJson = JSON.stringify(Json.respBody.flowApproves[0]);
	newFlowStepJson = jQuery.parseJSON(newFlowStepJson);
	newFlowStepJson.activityName = "新的节点";
	newFlowStepJson.id = rand;
	newFlowStepJson.step = nowLastStep + 1;
	var flowhtmlsActiveId = undefined;
	for (var i in newFlowStepJson.flowhtmls){		
		if (newFlowStepJson.flowhtmls[i] != null){
			newFlowStepJson.flowhtmls[i].activeId = rand;			
		}
	}
	Json.respBody.flowApproves.push(newFlowStepJson);
	initStepListDrop();
	initStepListClick();
}
	

//初始化步骤点击
function initStepListClick(){
	$('.gbin2-list').find("li").click(function(){
		$('.gbin2-list').find("li").each(function() {
            $(this).css("background-color","#f1f1f1");
        });
		$(this).css("background-color","#3CF");
		initStepInfo($(this).attr("id"),$(this).attr("step"));
	});
	$('.gbin2-list').find("li").find("div:nth-child(2)").unbind("click").click(function (){
		//删除步骤
		for (var i in Json.respBody.flowApproves){
			if (Json.respBody.flowApproves[i].id == $(this).parent().attr("id")){
				delete Json.respBody.flowApproves[i];
				$(this).parent().remove();
			}
		}
		
	});
}
//修改步骤控件属性
function changeWidget(j,i,type){
	switch(type){
		case "isDisplay":
			if (Json.respBody.flowApproves[j].flowhtmls[i].isDisplay == 1){
				Json.respBody.flowApproves[j].flowhtmls[i].isDisplay = 0;
			}else{
				Json.respBody.flowApproves[j].flowhtmls[i].isDisplay = 1;
			}
			break;
		case "isEdit":
			if (Json.respBody.flowApproves[j].flowhtmls[i].isEdit == 1){
				Json.respBody.flowApproves[j].flowhtmls[i].isEdit = 0;
			}else{
				Json.respBody.flowApproves[j].flowhtmls[i].isEdit = 1;
			}
			break;
		case "isNull":
			if (Json.respBody.flowApproves[j].flowhtmls[i].isNull == 1){
				Json.respBody.flowApproves[j].flowhtmls[i].isNull = 0;
			}else{
				Json.respBody.flowApproves[j].flowhtmls[i].isNull = 1;
			}
			break;
	}
	
}
//初始化步骤详细信息
function initStepInfo(id,st){
	var step = st ;
	$("#buzhouName").val($("#"+id).text());
	$("#buzhouName").unbind("blur").blur(function(e) {
        for (var j in Json.respBody.flowApproves){
			if (Json.respBody.flowApproves[j].step == step){
				Json.respBody.flowApproves[j].activityName = $("#buzhouName").val();
				$("#"+id+" > div:first-child").text($("#buzhouName").val());
			}
		}
    });
	
	//按步骤ID读取控件配置信息
	var str = "<ul>"
	for (var j in Json.respBody.flowApproves){
		if (Json.respBody.flowApproves[j].step == step){
			for (var i in Json.respBody.flowApproves[j].flowhtmls){
				str += "<li>"+Json.respBody.flowApproves[j].flowhtmls[i].chineseName+"</li>";
				str += "<li>";
				if (Json.respBody.flowApproves[j].flowhtmls[i].isDisplay == 1){
					str += " 显示<input type='checkbox' value='1' checked='checked' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isDisplay\")'>|";
				}else{
					str += " 显示<input type='checkbox' value='0' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isDisplay\")'>|";
				}
				if (Json.respBody.flowApproves[j].flowhtmls[i].isEdit == 1){
					str += " 可编辑<input type='checkbox' value='1' checked='checked' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isEdit\")'>|";
				}else{
					str += " 可编辑<input type='checkbox' value='0' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isEdit\")'>|";
				}
				if (Json.respBody.flowApproves[j].flowhtmls[i].isNull == 1){
					str += " 可为空<input type='checkbox' value='1' checked='checked' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isNull\")'>";
				}else{
					str += " 可为空<input type='checkbox' value='0' onclick='changeWidget(\""+j+"\",\""+i+"\",\"isNull\")'>";
				}
			}
		}
	}
	
	str += "</ul>";
	$("#liucheng_info_2").html(str);
	
	//按步骤ID读取基本配置信息
	routeConsole();
	var approveId;
	function routeConsole(){
		for (var j in Json.respBody.flowApproves){
			if (Json.respBody.flowApproves[j].step == step){
				approveId = Json.respBody.flowApproves[j].approveId;
				switch(Json.respBody.flowApproves[j].approveId){
					case undefined:
						$("#liucheng_info_1").find("input[type='radio']").eq(0).prop("checked", true);
						$("#jieshouren_juese").fadeOut();
						break;
					case "":
						$("#liucheng_info_1").find("input[type='radio']").eq(0).prop("checked", true);
						$("#jieshouren_juese").fadeOut();
						break;
					case "1":
						$("#liucheng_info_1").find("input[type='radio']").eq(1).prop("checked", true);
						$("#jieshouren_juese").fadeOut();
						break;
					case "2":
						$("#liucheng_info_1").find("input[type='radio']").eq(2).prop("checked", true);
						$("#jieshouren_juese").fadeOut();
						break;
					default:					
						$("#liucheng_info_1").find("input[type='radio']").eq(3).prop("checked", true);
						$("#jieshouren_juese").fadeIn();
				}
			}		
		}
	}
	
	//路由选项点击事件
	$('input[name="jieshouren"]').unbind("click").click(function(e) {
        //alert($(this).val());
		//保存路由ID
		for (var j in Json.respBody.flowApproves){
			if (Json.respBody.flowApproves[j].step == step){
				Json.respBody.flowApproves[j].approveId = $(this).val();
				routeConsole();
			}
		}
    });
	
	//角色选择器初始化
	var str1="";
	for (var i=0;i<ROLE.respBody.data.length;i++){
		str1 += "<p id='role_"+ROLE.respBody.data[i].id+"'>"+ROLE.respBody.data[i].name+"</p>";				
	}
	$("#jieshouren_juese").html(str1);
	$("#role_"+approveId).css("background-color","#06F");
	$("#role_"+approveId).css("color","#fff");
	
	//var y = $("#dep_"+depId).offset().top-300;
	//$(".rb_mainframe_middle").eq(1).mCustomScrollbar("scrollTo",y);
	$("#jieshouren_juese").find("p").click(function(){
		$("#jieshouren_juese").find("p").each(function() {
			$(this).css("background-color","transparent");
			$(this).css("color","#000");
		});
		$(this).css("background-color","#06F");
		$(this).css("color","#fff");
		//保存角色ID
		for (var j in Json.respBody.flowApproves){
			if (Json.respBody.flowApproves[j].step == step){
				Json.respBody.flowApproves[j].approveId = $(this).attr("id").substring(5,$(this).attr("id").length);
			}
		}
	});	
	
	$("#liucheng_info_2").mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});	
	
	$("#jieshouren_juese").mCustomScrollbar({
		theme:"dark",
		advanced:{updateOnContentResize:true}
	});
}
//保存新建的流程
function saveEditFlow(){
	$.ajax({
		timeout:2000, 
		type: AJAXMETHOD,
        async: false,
        url: SERVER + "defaultWorkFlow/editFlowNew?data=" + JSON.stringify(Json.respBody),
        dataType: AJAXJSON,
        jsonp: "callback",
        jsonpCallback:"callback",
        success: function(json){
			//dump(json);
			if (json.respCode == 0){			
				RB.Alert("系统提示","流程修改成功！点击\"确定\"查看流程列表，点击\"取消\"继续留着本页面！", "window.location.href='yygzl.html'");
			}else{
				RB.AlertInfo("系统提示","流程修改失败，失败原因:\""+json.respMessage+"\"");
			}
        },
        error: function(){
			RB.AlertInfo("系统提示","流程修改失败，请重新尝试修改！");
            //alert("createFlow error");
    	}
	});
}
//上传流程图标
function uploadIcon(){
	$('#flowIconForm').attr("action", SERVER+ "common/upload1").submit();
	var url=$("#flowIcon").val().split('\\');
	var exename=/\.[^\.]+$/.exec(url);//扩展名
	var img = $("#name").val();
	Json.respBody.flowTypexml.icons = "/rest/common/getAttachment?filePath="+img + exename;
	RB.Toast("<b>上传图标成功</b>");
	//$(".rb_newflow_icon").html("<img src='"+url + "common/getAttachment?filePath=" + img + exename+"'/>");
	/*
	$.ajax({
		cache: true,
		type: AJAXMETHOD,
		url:SERVER+ "common/upload1",
		dataType: AJAXJSON,
		data:$('#flowIconForm').serialize(),
		async: false,
		error: function() {
			alert("upload error");
		},
		success: function(data) {
			var url=$("#flowIcon").val().split('\\');
			var filename=url[arr.length-1];//文件名
			var exename=/\.[^\.]+$/.exec(my);//扩展名
			var img = $("#name").val();
			$(".rb_newflow_icon").find("img").attr("src",SERVER + "common/getAttachment?filePath=" + img + exename);
			alert(img + exename);
		}
	});
	*/
}

//////////////////////////////////////////////////////
$(document).ready(function() {
	initData();
			
	var fristwidth = (FRAMEWIDTH-40)*1/6;
	var secondwidth = (FRAMEWIDTH-40)*3/6;
	var threewidth = (FRAMEWIDTH-40)*2/6;
	$(".rb_mainframe_middle").eq(0).css("width",fristwidth+"px");
	$(".rb_mainframe_middle").eq(1).css("width",secondwidth+"px");
	$(".rb_mainframe_middle").eq(1).css("left",fristwidth+10+"px");
	$(".rb_mainframe_middle").eq(2).css("width",threewidth+"px");
	$(".rb_mainframe_middle").eq(2).css("left",fristwidth+secondwidth+20+"px");
	$(".rb_newflow_kongjian_setup").eq(0).css("width",(FRAMEWIDTH-40)*3/6-310+"px");
	//$("#createFlow").css("width",(FRAMEWIDTH-40)*3/6-350+"px");
	$(".rb_newflow_kongjian_setup").eq(1).css("width",(FRAMEWIDTH-40)*2/6-100-45+"px");
	$("#liucheng_kongjian_list").css("height",FRAMEHEIGHT-125-$("#creatFlow").height()+"px");	
	
	$(".rb_newflow_kongjian_iphone_screen").mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});
	
	$(".rb_newflow_liucheng").mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});
	
	$(".rb_newflow_liucheng").css("height",$(".rb_mainframe_middle").height()-40+"px");	
	
	//步骤标签样式初始化
	$(".liucheng_info").css("height",$("#liucheng_kongjian_list").height()-32+"px");
	$(".liucheng_info").css("width",$("#liucheng_kongjian_list").width()-2+"px");
	$("#liucheng_info_1").mCustomScrollbar({
    	theme:"dark",
		advanced:{updateOnContentResize:true}
	});	
	
	//步骤属性页Tab切换
	$("#liucheng_change_btn_1").unbind("click").click(function(){
		$("#liucheng_info_1").show();
		$("#liucheng_info_2").hide();
		$(this).css("background-color","#ccc");
		$(this).css("color","#fff");
		$("#liucheng_change_btn_2").css("background-color","transparent");
		$("#liucheng_change_btn_2").css("color","#999");		
	});
	$("#liucheng_change_btn_2").unbind("click").click(function(){
		$("#liucheng_info_2").show();
		$("#liucheng_info_1").hide();
		$(this).css("background-color","#ccc");
		$(this).css("color","#fff");
		$("#liucheng_change_btn_1").css("background-color","transparent");
		$("#liucheng_change_btn_1").css("color","#999");		
	});
	
	//监听图标上传
	$("#flowIcon").bind("change").change(function(e) {
		if ($(this).val().length>0){
			var times = new Date().DateFormat("yyyyMMddhhmmssS");
			$("#name").val(times);
			uploadIcon();
		}
    });
	
});